import Scene from "./Scene";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SceneHall extends Scene {

    @property(cc.Node)
    btnBox: cc.Node = null;

    private _btns: cc.Node[];
    private _allScenes: string[];

    protected onLoad(): void {
        super.onLoad();
        this._allScenes = ["A_Base", "B_Render", "C_Ad", "D_View", "E_Net",
            "F_Share", "G_Pay", "H_Storage", "I_Media", "J_Position",
            "K_File", "L_Open", "M_Device", "N_Worker"];
        this._btns = [];
        let btn: cc.Node;
        for (let i = 0; i < 14; i++) {
            btn = this.btnBox.getChildByName('btn_' + (i + 1));
            this._btns[i] = btn;
        }
    }

    protected onEnable(): void {
        super.onEnable();
        let btn: cc.Node;
        for (let i = 0; i < this._btns.length; i++) {
            btn = this._btns[i];
            btn.on(cc.Node.EventType.TOUCH_END, this.onTouch, this);
        }
    }

    protected onDisable(): void {
        let btn: cc.Node;
        for (let i = 0; i < this._btns.length; i++) {
            btn = this._btns[i];
            btn.off(cc.Node.EventType.TOUCH_END, this.onTouch, this);
        }
        super.onDisable();
    }

    private onTouch(event: cc.Event.EventTouch): void {
        let index: number = this._btns.indexOf(event.target);
        if (index == -1) {
            return;
        }
        let scene: string = this._allScenes[index];
        this.gotoScene(scene);
    }
}
